import axios from '../utils/request.js';

const ApiService = {
  get(url, params) {
    return axios.request({
      url,
      params,
      method: 'GET'
    })
  },
  post(url, data) {
    return axios.request({
      url,
      data,
      method: 'POST'
    })
  },
  put(url, data) {
    return axios.request({
      url,
      data,
      method: 'PUT'
    })
  },
  upload(url, data) {
    return axios.request({
      url,
      data,
      method: 'POST',
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

export const UserService = {
  // 获取用户列表
  getList(params) {
    return ApiService.get('/users', params);
  },
  // 获取下级部门的职工列表
  getUnder(params) {
    return ApiService.get('/users_list/get_user_list', params);
  },

  addUser(params) {
    return ApiService.post('/users', params);
  },

  getInfo(params) {
    return ApiService.get('/user/info', params);
  },

  login(data) {
    return ApiService.post('/login', data)
  },

  is_login(params) {
    return ApiService.get('/user/is_login', params);
  }
}

export const VisitService = {
  visit(data) {
    return ApiService.post('/return_visit',data)
  },
  visit_logs(data) {
    return ApiService.get('/return_visit',data)
  }
}

export const ShoperService = {
  // 获取加盟商列表
  getList(params) {
    return ApiService.get('/franchisees', params)
  },
  // 获取单个加盟商
  getOne(params, id) {
    return ApiService.get('/franchisees/' + id, params)
  },
  // 验证单个加盟商
  verifyOne(params, id) {
    return ApiService.post('/franchisees/verify/' + id, params)
  },
  addShoper(data) {
    return ApiService.post('/franchisees', data)
  },

  editShoper(data, shoper_id) {
    return ApiService.put('/franchisees/' + shoper_id, data)
  },

  addCar(data, shoper_id) {
    return ApiService.post('/system/add_car/' + shoper_id, data)
  },

  editCar(data, shoper_id) {
    return ApiService.post('/system/edit_car/' + shoper_id, data);
  },

  addSale(data, shoper_id) {
    return ApiService.post('/franchisee/add_sale_task/' + shoper_id, data);
  },

  addMoney(data, shoper_id) {
    return ApiService.post('/system/recharge/' + shoper_id, data);
  },

  addAmount(data, shoper_id) {
    return ApiService.post('/franchisees/car/add_amount/' + shoper_id, data);
  }
}


export const RegionService = {
  // 获取地区信息
  getRegion(params = {}) {
    return ApiService.get('/regions', params)
  }
}

export const SystemService = {
  upload(data) {
    return ApiService.upload('/upload/image', data)
  },
  water_bill(data) {
    return ApiService.get('/franchisees/statistics/finance', data);
  },
  
}

export const HomeService = {
  // 首页加盟车总量加盟车增长等统计数据
  getTotal(params = {}) {
    return ApiService.get('/index', params)
  },
  // 首页获取加盟车增长趋势
  getTrend(params = {}) {
    return ApiService.get('/index/car_add_trand', params)
  },
  // 首页业绩统计
  getResult(params = {}) {
    return ApiService.get('/index/achievement', params)
  },
  // 首页销量统计
  getSale(params = {}) {
    return ApiService.get('/index/sales_volume', params)
  }
}

export const JobService = {
  getList(params = {}) {
    return ApiService.get('/jobs', params)
  }
}

export const DeptService = {
  getList(params = {}) {
    return ApiService.get('/departments', params)
  }
}

export const RoleService = {
  getList(params = {}) {
    return ApiService.get('/roles', params)
  }
}

export const ChargeService = {
  // 给加盟车或加盟商充值
  charge(data) {
    return ApiService.post('/system/recharge' , data);
  },
  purchase(data) {
    return ApiService.post('/system/purchase', data)
  },
  // 加盟商资金变动记录
  finance_logs(params) {
    return ApiService.get('/finance_logs',params)
  }
}